/*
 * main.cpp
 *
 *  Created on: Jun 28, 2013
 *      Author: bq_jsoine
 */

//#include "implementation/controller/TestController.h"
#include "implementation/controller/ACM_FEM_SeparateCG_Controller.h"
#include "implementation/controller/ACMFA_FEM_SeparateCG_Controller.h"
#include "implementation/controller/Sampling_ACM_FEM_Controller.h"
#include <iostream>
#include <string>

using namespace std;

void print_help();

int main(int argc, char* argv[]) {

	string version = "1.0.0";
	string parameter_file;
	bool input_file_found = false;
	for (int i = 1; i < argc; i++)
		if (strchr(argv[i], '.prm') != NULL) {
			cout << "Read input file " << argv[i] << endl;
			parameter_file = argv[i];
			input_file_found = true;
		}

	for (int i = 1; i < argc; i++)
		if (strncmp(argv[i], "--help", 6) == 0 && strlen(argv[i]) == 6)
			print_help();

	for (int i = 1; i < argc; i++)
		if (strncmp(argv[i], "--version", 9) == 0 && strlen(argv[i]) == 9) {
			cout << "MBTFM version " << version << endl;
			exit(0);
		}

	if (!input_file_found)
		cout << "ERROR: no input file found. -> give input file as argument"
				<< endl;
	else {
		for (int i = 1; i < argc; i++)
			if (strncmp(argv[i], "--ACMFA", 7) == 0 && strlen(argv[i]) == 7) {
				ACMFA_FEM_SeparateCG_Controller control(parameter_file);
				exit(0);
			}
		for (int i = 1; i < argc; i++)
			if (strncmp(argv[i], "--ACM", 5) == 0 && strlen(argv[i]) == 5) {
				ACM_FEM_SeparateCG_Controller control(parameter_file);
				exit(0);
			}
		for (int i = 1; i < argc; i++)
			if (strncmp(argv[i], "--SAMPLING", 10) == 0
					&& strlen(argv[i]) == 10) {
				string dsf_stat_file = argv[i + 1];
				string tva_stat_file = argv[i + 2];
				string vsf_stat_file = argv[i + 3];
				int n_iterations = atoi(argv[i + 4]);
				Sampling_ACM_FEM_Controller control(parameter_file,
						dsf_stat_file, tva_stat_file, vsf_stat_file,
						n_iterations);
				exit(0);
			}

		cout << "Nothing to do!" << endl;
		exit(0);
	}
}

void print_help() {
	cout << "Model-based Traction Force Reconstruction Programm" << endl;
	cout << "--------------------------------------------------" << endl
			<< endl;
	cout << "Syntax: MBTFM <parameter_filename> <options> " << endl << endl;
	cout << "Methods:" << endl;
	cout << "--FA               use FA constraint optimization with FEM"
			<< endl;
	cout
			<< "--FAHS             use FA constraint optimization and halfspace approximation and circlar loads"
			<< endl;
	cout
			<< "--REGFAHS          use FA constraint optimization and halfspace approximation and circlar loads with regularization. Syntax: MBTFM --REGFAHS reg_param(double) optimization_quantity(1:traction, 2:force) regularization_quantity(1:traction, 2:force, 3:traction*area, 4:force*area) <parameter_file>"
			<< endl;
	cout
			<< "--ACMFA            use FA constraint optimization with (A)ctive (C)able (M)odel"
			<< endl << endl;
	cout << "--ACM              use (A)ctive (C)able (M)odel" << endl << endl;
	cout
			<< "--CUT              CUT Active Cable Model with FA ellipses, no optimization"
			<< endl << endl;
	cout
			<< "--SAMPLING <dsf_stat_file> <tva_stat_file> <vsf_stat_file>  <n_iterations>   sample based on given distribitions"
			<< endl << endl;
	cout << "Options:" << endl;
	cout << "--version          prints number of program version" << endl;
	cout << "--help             print help" << endl;
	exit(0);

}
